package com.brioal.swipemenudemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.brioal.swipemenu.view.SwipeMenu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

public class AnlineActivity extends AppCompatActivity implements View.OnClickListener{
    @Bind(R.id.main_swipemenu)
    SwipeMenu AnlineSwipeMenu;
    @Bind(R.id.main_btn_menu)
    ImageButton imageButton;
    @Bind(R.id.menu_list)
    ListView listView_menu;
    @Bind(R.id.to_more)
    TextView to_more;
    private String[] mTitles = {
            "我的订单",
            "我的钱包",
            "专属客服",
            "资料交接",
            "使用说明",
    };
    private int[] mIds = {
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
    };
    private String[] mDescs = {
            "订单管理",
            "资金管理",
            "专属服务",
            "资料交接",
            "使用帮助",
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme_NoActionBar);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anline);
        ButterKnife.bind(this);
        AnlineSwipeMenu.setBackImage(AnlineActivity.this,R.mipmap.mountain,R.color.colorAccent);
//        加下一句不沉浸左边图片背景
//        AnlineSwipeMenu.setChangedBlur(AnlineActivity.this, R.mipmap.mountain, R.color.colorPrimary);
        AnlineSwipeMenu.setStart3DAngle((int) (0.5 * 1.0f / 100 * 90));
        AnlineSwipeMenu.setStartAlpha(1 * 1.0f / 100);
        AnlineSwipeMenu.setStartScale(1 * 1.0f / 100);
        AnlineSwipeMenu.setStyleCode(3222);
        imageButton.setOnClickListener(this);
//        菜单列表
        List listData = new ArrayList();
        for (int i = 0;i < mTitles.length; i++){
            Map mItem = new HashMap();
            mItem.put("title",mTitles[i]);
            mItem.put("desc",mDescs[i]);
            mItem.put("img",mIds[i]);
            listData.add(mItem);
        }
        SimpleAdapter mAdapter = new SimpleAdapter(getApplicationContext(),listData,R.layout.listview_menu_item,new String[]{"title","img"},new int[]{R.id.item_title,R.id.item_icon});
        listView_menu.setAdapter(mAdapter);

        listView_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(getApplicationContext(),"点击了："+mTitles[i],Toast.LENGTH_SHORT).show();
            }
        });
        to_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(),MainActivity.class));
            }
        });
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.main_btn_menu:
                if (AnlineSwipeMenu.isMenuShowing()) {
                    AnlineSwipeMenu.hideMenu();
                } else {
                    AnlineSwipeMenu.showMenu();
                }
                break;
        }
    }
}
